package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendUserService {
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if (null == recommendUser) {
            return null;
        }
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        todayBest.setFateValue(Double.valueOf(Math.floor(recommendUser.getScore())).longValue());
        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        return this.recommendUserApi.queryPageInfo(id, page, pagesize);
    }

    public Double queryScore(Long userId, Long id) {
        Double score = recommendUserApi.queryScore(userId, id);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        return 98d;
    }

    public List<RecommendUser> queryCardList(Long id, int count) {
        return recommendUserApi.queryCardList(id, count);
    }
}
